home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
016a
/
frbts_20.zip
/
FRGET.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-27
|
8KB
|
310 lines
/****************************************************************************/
/* */
/* Fget.c Version 2.0 By Craig Derouen */
/* Add on util for Frobot. */
/* */
/* */
/****************************************************************************/
/* This version is written in Microsoft C 6.0. Version 1.x was Microsoft
C 5.X but I lost the source code so I had to re-write this the hard
way!
*/
#include "frobot.h"
#include "share.h"
char temp[100];
char temp1[100];
struct stat fbuf;
char ScriptFile[65];
char ScrCmnd[5];
char FileName[66];
char NodeStr[20];
char DateStr[20];
char TimeStr[20];
char ScrMode[5];
char ScrTimes[5];
char hdir[_MAX_DIR];
char hdrive[_MAX_DRIVE];
int ExitCode;
int ShowActivity = TRUE;
int Silent = FALSE;
int getparms(char *ctlfile);
int checkparms(void);
void promptparms(void);
void writeparms(void);
void striptail(char *p);
int main(int argc,char **argv)
{
char strng[65];
/* Parse out the drive and dir where frobot is located */
_splitpath(argv[0],hdrive,hdir,temp,temp1); /* Ignore name and extension */
strcpy(strng,"Frobot.ctl"); /* Try current dir first */
if(stat(strng,&fbuf) == -1) { /* Not there, try fget dir */
_makepath(strng,hdrive,hdir,"Frobot",".CTL");
if(stat(strng,&fbuf) == -1) { /* Not there, try Binkley env */
strcpy(strng,getenv("BINKLEY"));
if (!*strng) {
printf("Missing Frobot parameter file\n");
warble();
exit(1);
}
striptail(strng);
strcat(strng,"\\Frobot.ctl");
if(stat(strng,&fbuf) == -1) { /* Not there, give up */
printf("Missing Frobot parameter file\n");
warble();
exit(1);
}
}
}
if(getparms(strng)) {
printf("Error processing Frobot parameter file\n");
warble();
ExitCode = 1;
}
if (argc >= 7) { /* It's on the command line */
strcpy(ScrCmnd,argv[1]);
strcpy(FileName,argv[2]);
strcpy(NodeStr,argv[3]);
strcpy(DateStr,argv[4]);
strcpy(TimeStr,argv[5]);
strcpy(ScrMode,argv[6]);
if (argc >= 8)
strcpy(ScrTimes,argv[7]);
}
else if(argc < 2) /* We must do a prompt mode */
promptparms();
if(checkparms()) {
printf("Invalid parameters, exiting\n");
warble();
ExitCode = 1;
}
else writeparms();
return(ExitCode);
}
/* Parse out the parameter file */
int getparms(char *ctlfile)
{
FILE *infile;
char *p1,*p2;
int checkcount = 0;
if ((infile = _fsopen(ctlfile,"rt",SH_DENYNO)) == NULL)
return(TRUE); /* Say there's an error */
fgets(temp,81,infile);
while (!feof(infile)) {
if (*temp) { /* Parse out token string */
p1 = strtok(temp," \n\t");
p2 = strtok(NULL," \n\t;");
if (*p1 == ';') { /* Just ignore comment lines */
fgets(temp,81,infile);
continue;
}
if (strcmpi(p1,"scriptloc") == 0) {
if (p2) {
strcpy(ScriptFile,p2);
checkcount++;
}
}
else if (strcmpi(p1,"bells") == 0) {
if (p2){
if (strcmpi(p2,"Yes") == 0)
Silent = FALSE;
else Silent = TRUE;
}
}
}
fgets(temp,81,infile);
}
fclose(infile);
if (checkcount < 1)
return(2); /* Not all the necessary parameters were found */
return(FALSE);
}
/* Test the validity of parameters */
int checkparms(void)
{
int x;
/* Check out command mode */
x = strlen(ScrCmnd);
if (x > 2 || x < 1)
return 1;
x = tolower(*ScrCmnd);
if (x != 'r' && x != 's')
return 1;
/* Check out filename */
if(strlen(FileName) < 1)
return 1;
/* Check out net/node */
if (strlen(NodeStr) < 3)
return 1;
if (strchr(NodeStr,'/') == NULL)
return 1;
/* Check out the date */
if (strchr(DateStr,'/') == NULL) { /* It's a special macro */
if (strlen(DateStr) < 3)
return 1;
x = TRUE; /* Assume it's bad */
strncpy(temp,DateStr,3); /* We only need 3 for testing */
temp[3] = 0;
if (strcmpi(temp,"NOW") == 0)
x = FALSE;
else if (strcmpi(temp,"Sun") == 0)
x = FALSE;
else if (strcmpi(temp,"Mon") == 0)
x = FALSE;
else if (strcmpi(temp,"Tue") == 0)
x = FALSE;
else if (strcmpi(temp,"Wed") == 0)
x = FALSE;
else if (strcmpi(temp,"Thu") == 0)
x = FALSE;
else if (strcmpi(temp,"Fri") == 0)
x = FALSE;
else if (strcmpi(temp,"Sat") == 0)
x = FALSE;
if (x) return 1;
}
else if (strlen(DateStr) > 8 || strlen(DateStr) < 5)
return 1;
/* Check out the time */
if (strchr(TimeStr,':') == NULL) { /* It's a special macro */
if (strcmpi(TimeStr,"NOW") != 0)
return 1;
}
else if (strlen(TimeStr) > 5 || strlen(TimeStr) < 4)
return 1;
/* check out flo mode */
if (strlen(ScrMode) > 1)
return 1;
x = tolower(*ScrMode);
if (x != 'c' && x != 'h' && x != 'd' && x != 'd')
return 1;
return 0;
}
void promptparms(void)
{
while (1) {
printf("Enter Script command. 'S' for send or 'R' for request file: ");
gets(temp);
blanktrim(temp);
if (*temp > '!') {
strcpy(ScrCmnd,temp);
break;
}
}
while (1) {
printf("Enter FileName: ");
gets(temp);
blanktrim(temp);
if (*temp > '!') {
strcpy(FileName,temp);
break;
}
}
while (1) {
printf("Enter Net/Node (Zone is optional but ignored): ");
gets(temp);
blanktrim(temp);
if (*temp > '!') {
strcpy(NodeStr,temp);
break;
}
}
while (1) {
printf("Enter start date (day of week,'NOW', or mm/dd/yr): ");
gets(temp);
blanktrim(temp);
if (*temp > '!') {
strcpy(DateStr,temp);
break;
}
}
while (1) {
printf("Enter start time ('NOW' or 24 hour format HH:MM): ");
gets(temp);
blanktrim(temp);
if (*temp > '!') {
strcpy(TimeStr,temp);
break;
}
}
while (1) {
printf("Enter flow mode. 'C' for crash,'D' for direct,'N' for normal\n");
printf("\t or 'H' for hold: ");
gets(temp);
blanktrim(temp);
if (*temp > '!') {
strcpy(ScrMode,temp);
break;
}
}
if ( tolower(*ScrCmnd) == 'r') {
printf("Enter # of times to request file: ");
gets(temp);
blanktrim(temp);
if (*temp)
strcpy(ScrTimes,temp);
else strcpy(ScrTimes,"1");
}
}
void writeparms(void)
{
FILE *fl;
if ((fl = _fsopen(ScriptFile,"at",SH_DENYWR)) == NULL) {
printf("Error opening scriptfile: %s, exiting\n",ScriptFile);
warble();
exit(1);
}
fseek(fl,0L,SEEK_END);
sprintf(temp,"%s %s %s %s %s %s ",ScrCmnd,FileName,NodeStr,DateStr,TimeStr,ScrMode);
if (*ScrTimes)
strcat(temp,ScrTimes);
strcat(temp,"\n");
fputs(temp,fl);
fclose(fl);
}
/* Check dirpath and remove tail dir sep if its there */
void striptail(char *p)
{
int x;
x = strlen(p) - 1;
if (p[x] == '\\')
p[x] = 0;
}